package com.sunda.spmsweb.wmscontroller;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.sunda.spmscommon.ResponseResult;
import com.sunda.spmswms.service.IWithdrawTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 移动冲销表 前端控制器
 * </p>
 *
 * @author Wayne
 * @since 2021-04-25
 */
@RestController
@RequestMapping("/withdrawTask")
@Api(tags = "仓库冲销接口", description = "仓库冲销接口")
public class WithdrawTaskController {

    @Autowired
    IWithdrawTaskService iWithdrawTaskService;

    @PostMapping("/getWithdrawTasks")
    @ApiOperation(value = "按条件查询冲销历史记录",notes = "按条件查询冲销历史记录 \n" +
            "userId:\"999904\"  创建人工号\n" +
            "deliveryNoteSap:\"deliveryNoteSap\"  交货单号 \n" +
            "mobileType:\"1\"     1入库冲销；2出库冲销\n" +
            "taskCategory:\"1\"     任务类别 X 备件货，M 贸易货\n" +
            "relatedTaskId:\"1\"     关联单号\n")
    ResponseResult getWithdrawTasks(String userId,String deliveryNoteSap,String mobileType,String taskCategory,String relatedTaskId) {
       try {
           return iWithdrawTaskService.getWithdrawTasks(userId,deliveryNoteSap,mobileType,taskCategory,relatedTaskId);
       }catch (Exception e){
           e.printStackTrace();
           return ResponseResult.error("Error when query Withdraw Tasks");
       }
    }

    @GetMapping("getwithdrawTaskDtl")
    @ApiOperation(value="获取指定Withdraw单据的详情",notes="获取指定Withdraw单据的详情" +
    "uuid: \"storage UUID\"")
    ResponseResult getwithdrawTaskDtl(@RequestParam String uuid){
        if(StringUtils.isEmpty(uuid)){
            return ResponseResult.error("uuid is mandatory required");
        }
        return iWithdrawTaskService.getwithdrawTaskDtl(uuid);
    }

    @PostMapping("/getWithdrawableList")
    @ApiOperation(value="按条件搜索可撤销的单据",notes="按条件搜索可撤销的单据" +"{\n" +
            "  \"deliveryNoteSap\":\"deliveryNoteSap\",\n" +
            "  \"datePeriod\":[\"2021-04-01\",\"2021-04-30\"],\n" +
            "  \"mobileType\":\"101\"\n" +
            "}")
    ResponseResult getWithdrawableList(@RequestBody JSONObject jsonObject){
        return iWithdrawTaskService.getWithdrawableList(jsonObject);
    }
}
